package com.victor.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.victor.dao.JingquDao;
import com.victor.entity.city.CityCenterLocation;
import com.victor.entity.collection.JqCollection;
import com.victor.entity.jingqu.Jingdianintroduce;
import com.victor.entity.jingqu.Jingdiantupian;
import com.victor.entity.jingqu.Jingquclass;
import com.victor.entity.jingqu.Jingqujingdian;
import com.victor.entity.jingqu.Jingqulist;
import com.victor.entity.jingqu.JingquticketIntroduce;
import com.victor.entity.jingqu.Jingqutupian;
import com.victor.entity.praise.JqcommentPraise;
import com.victor.service.JingquService;
import com.victor.utils.LocationUtils;

@Service
public class JingquServiceImpl implements JingquService {

	@Autowired
	private JingquDao dao;

	// 获取所有景区类别
	@Override
	public List<Jingquclass> getClassList() {
		return dao.getClassList();
	}

	// 添加景区类型
	@Override
	public boolean addClass(Jingquclass jingquclass) {
		return dao.addClass(jingquclass) > 0 ? true : false;
	}

	// 修改类别信息
	@Override
	public boolean updateClass(Jingquclass jingquclass) {
		return dao.updateClass(jingquclass) > 0 ? true : false;
	}

	// 删除类别
	@Override
	public boolean deleteClass(int[] cids) {
		return dao.deleteClass(cids) > 0 ? true : false;
	}

	// 获取景区列表
	@Override
	public List<Jingqulist> getJQlist(String jqclassid, String starttime, String endtime, String searchname) {
		return dao.getJQlist(jqclassid, starttime, endtime, searchname);
	}

	// 新建景区--添加景区信息
	@Override
	public boolean buildJQ(Jingqulist jingqulist) {
		return dao.buildJQ(jingqulist) > 0 ? true : false;
	}

	// 添加景区图片信息
	@Override
	public boolean addJingqutupian(Jingqutupian jingqutupian) {
		return dao.addJingqutupian(jingqutupian) > 0 ? true : false;
	}

	// 批量删除
	@Override
	public boolean batchDeleteJQ(int[] jqids) {
		return dao.batchDeleteJQ(jqids) > 0 ? true : false;
	}

	// 景区详情
	@Override
	public Jingqulist getJQxqByid(String jqid) {
		return dao.getJQxqByid(jqid);
	}

	// 修改景区信息
	@Override
	public boolean updateJQ(Jingqulist jingqulist) {
		return dao.updateJQ(jingqulist) > 0 ? true : false;
	}

	// 添加景点
	@Override
	public boolean addJingdian(Jingqujingdian jingqujingdian) {
		return dao.addJingdian(jingqujingdian) > 0 ? true : false;
	}

	// 添加景点图片
	@Override
	public boolean addJingdiantupian(Jingdiantupian jingdiantupian) {
		return dao.addJingdiantupian(jingdiantupian) > 0 ? true : false;
	}

	// 删除景点
	@Override
	public boolean deleteJingdianByid(String jdid) {
		return dao.deleteJingdianByid(jdid) > 0 ? true : false;
	}

	// 添加景点简介
	@Override
	public boolean addJdintroduce(Jingdianintroduce jingdianintroduce) {
		return dao.addJdintroduce(jingdianintroduce) > 0 ? true : false;
	}

	// 修改景点
	@Override
	public boolean updateJD(Jingqujingdian jingqujingdian) {
		return dao.updateJD(jingqujingdian);
	}

	// 删除景点原图片
	@Override
	public boolean deleteJingdianTup(Integer jdid) {
		return dao.deleteJingdianTup(jdid) > 0 ? true : false;
	}

	// 删除景点原简介
	@Override
	public boolean deleteJingdianJJ(Integer jdid) {
		return dao.deleteJingdianJJ(jdid) > 0 ? true : false;
	}

	@Override
	public PageInfo<Jingqulist> getJingquListAll(int page, int row) {
		PageHelper.startPage(page, row);
		List<Jingqulist> list = dao.selAll();
		if (list != null && list.size()>0) {
			for (int i = 0; i < list.size(); i++) {
				List<Jingqutupian> tupian = dao.selJingqutupianById(list.get(i).getId());
				if (tupian == null || tupian.size()<=0) {
					list.get(i).setPhoto(null);
				}else {
					list.get(i).setPhoto(String.valueOf(tupian.get(0).getJqphoto()));
				}
				
			}
		}
		return new PageInfo<>(list, 5);
	}

	@Override
	public PageInfo<Jingqulist> selByCondition(HashMap<Object, Object> map,int page,int row) {
		PageHelper.startPage(page, row);
		List<Jingqulist> list = dao.selByCondition(map);
		if (list != null && list.size()>0) {
			for (int i = 0; i < list.size(); i++) {
				List<Jingqutupian> tupian = dao.selJingqutupianById(list.get(i).getId());
				if (tupian == null || tupian.size()<=0) {
					list.get(i).setPhoto(null);
				}else {
					list.get(i).setPhoto(String.valueOf(tupian.get(0).getJqphoto()));
				}
				
			}
		}
		return new PageInfo<>(list, 5);
	}

	@Override
	public int deleteList(int[] ids) {
		return dao.deleteByPrimaryKey(ids);
	}

	@Override
	public List<Jingqulist> getAllListNopageandrow() {
		return dao.selAll();
	}

	@Override
	public Jingqulist selByJqid(String jqid) {
		return dao.selectByPrimaryKey(jqid);
	}


	@Override
	public Jingqulist selByJqidAndUid(String jqid, String uid) {
		return dao.selectByPrimaryKeyAndUid(jqid,uid);
	}

	@Override
	public PageInfo<Jingqulist> selMoreCondition(String search,String city, String classid, String level, String area,  int page, int row,String mylon,String mylat) {
		PageHelper.startPage(page, row);
		List<Jingqulist> list = dao.selList(city,classid,level,area,search);
		for (int j = 0; j < list.size(); j++) {
			String distance = LocationUtils.getDistance(mylon, mylat, list.get(j).getJqlocation_lon(), list.get(j).getJqlocation_lat());
			list.get(j).setDistance(distance);
		}
		return new PageInfo<>(list, 5);
	}

	@Override
	public List<Jingqulist> selByCity(String city) {
		return dao.selByCity(city);
	}

	@Override
	public CityCenterLocation selCenterCityByName(String city) {
		return dao.selCityCenLocation(city);
	}

	@Override
	public List<Jingqulist> selShaixuan(String screening, String city) {
		return dao.selShaiXuan(screening,city);
	}

	@Override
	public JingquticketIntroduce selTicketIntroduceByTid(String id) {
		return dao.selTicketIntroduceByTid(id);
	}


}
